package cn.bgs.controller;


import cn.bgs.common.R;
import cn.bgs.pageUtil.PageRequest;
import cn.bgs.pojo.VehicleArea;
import cn.bgs.service.IVehicleAreaService;
import io.swagger.annotations.ApiOperation;
import cn.bgs.vo.AreaVo;
import cn.bgs.vo.CommunityVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 车位区域表 前端控制器
 * </p>
 *
 * @author cf
 * @since 2022-06-07
 */
@RestController
@RequestMapping("/vehicle-area")
public class VehicleAreaController {
    @Autowired
    IVehicleAreaService iVehicleAreaService;

    @RequestMapping("/selectAreaInfo")
    public R selectAreaInfo(@RequestBody AreaVo areaVo){
//        System.out.println("----:"+vehicleArea);
        return iVehicleAreaService.selectAreaInfo(areaVo);
    }

    @PostMapping("/updateAreaInfo")
    public R updateAreaInfo(@RequestBody VehicleArea vehicleArea){
        if (iVehicleAreaService.updateAreaInfo(vehicleArea)){
            return R.ok();
        }
        return R.error();
    }

    @PostMapping("/addAreaInfo")
    public R addAreaInfo(@RequestBody VehicleArea vehicleArea){
        boolean a = iVehicleAreaService.addAreaInfo(vehicleArea);
        return R.ok().data("data",a);
    }

    @GetMapping("/deleteCarInfo")
    public R deleteCarInfo(Integer vehicleAreaId){
        return iVehicleAreaService.deleteCarInfo(vehicleAreaId);
    }
    //    查询小区信息
    @GetMapping("/info")
    public R info(CommunityVo communityVo){
        return iVehicleAreaService.info(communityVo);
    }
//     查询车位信息信息
    @RequestMapping("selectCarInfo")
    public R selectCarInfo(@RequestBody PageRequest request){
        return iVehicleAreaService.selectCarInfo(request);
    }


    //车行区域全查
    @GetMapping("/carAreaList")
    public R carAreaList(Integer pageNum,Integer pageSize){
        PageRequest pageRequest = new PageRequest();
        if(pageNum==null){
            pageNum=1;
        }else {
            pageRequest.setPageNum(pageNum);
        }
        if (pageSize==null){
            pageSize=10;
        }else {
            pageRequest.setPageSize(pageSize);
        }
        return iVehicleAreaService.carAreaList(pageRequest);
    }

    //车行区域删除
    @DeleteMapping("/delete/{id}")
    public Object carDelet(@PathVariable Integer id){
        return iVehicleAreaService.carDelete(id);
    }



    @GetMapping("/appFindVehicleArea/{communityId}")
    @ApiOperation(value = "app我的车位(添加车位信息查询)")
    public R appFindVehicleArea(@PathVariable Integer communityId){

        List<VehicleArea> vehicleAreas = iVehicleAreaService.appFindVehicleArea(communityId);
        if (vehicleAreas != null){
            return R.ok().data("vehicleAreas",vehicleAreas);
        }else {
            return R.error();
        }
    }
    //车行区域添加
    @PostMapping("/pcAddCar")
    public R pcAddCar(@RequestBody VehicleArea vehicleArea){
        R r = iVehicleAreaService.pcAddCar(vehicleArea);
        return r;
    }
}
